package io.kiki.sba.registry.common.model.metaserver;

import com.google.common.base.Objects;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.Set;


@Getter
public class MultiClusterSyncInfo {


    @Setter
    private String dataCenter;

    /**
     * sync remote data center
     */
    @Setter
    private String remoteDataCenter;

    /**
     * remote meta address, use to get meta leader
     */
    @Setter
    private String remoteMetaAddress;

    /**
     * multi sync switch
     */
    @Setter
    private boolean enableSyncDatum;

    /**
     * push switch
     */
    @Setter
    private boolean enablePush;

    /**
     * allow sync multi group
     */
    private Set<String> synPublisherGroups = new HashSet<>();

    /**
     * allow sync multi dataInfoId
     */
    private Set<String> syncDataInfoIds = new HashSet<>();

    /**
     * dataInfoId will not multi sync, this priority is higher than syncGroups and syncDataInfoIds
     */
    private Set<String> ignoreDataInfoIds = new HashSet<>();

    /**
     * data version
     */
    @Setter
    private long dataVersion;

    public MultiClusterSyncInfo() {
    }

    public MultiClusterSyncInfo(String remoteDataCenter, String remoteMetaAddress, long dataVersion) {
        this.remoteDataCenter = remoteDataCenter;
        this.remoteMetaAddress = remoteMetaAddress;
        this.dataVersion = dataVersion;
    }

    public MultiClusterSyncInfo(String dataCenter, String remoteDataCenter, String remoteMetaAddress, long dataVersion) {
        this.dataCenter = dataCenter;
        this.remoteDataCenter = remoteDataCenter;
        this.remoteMetaAddress = remoteMetaAddress;
        this.dataVersion = dataVersion;
    }

    public MultiClusterSyncInfo(String dataCenter, String remoteDataCenter, String remoteMetaAddress, boolean enableSyncDatum, boolean enablePush, Set<String> syncDataInfoIds, Set<String> synPublisherGroups, Set<String> ignoreDataInfoIds, long dataVersion) {
        this.dataCenter = dataCenter;
        this.remoteDataCenter = remoteDataCenter;
        this.remoteMetaAddress = remoteMetaAddress;
        this.enableSyncDatum = enableSyncDatum;
        this.enablePush = enablePush;
        this.syncDataInfoIds = syncDataInfoIds;
        this.synPublisherGroups = synPublisherGroups;
        this.ignoreDataInfoIds = ignoreDataInfoIds;
        this.dataVersion = dataVersion;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MultiClusterSyncInfo that = (MultiClusterSyncInfo) o;
        return Objects.equal(dataCenter, that.dataCenter) && Objects.equal(remoteDataCenter, that.remoteDataCenter);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(dataCenter, remoteDataCenter);
    }


}
